﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using FMSpaceShooter.Screens;
using FMSpaceShooter.ScreenManager;

namespace FMSpaceShooter.GameObjects
{
    abstract class BulletBase : ObjectBase
    {
        DateTime? outOfBounds = null;
        TimeSpan outOfBoundsTimeLimit = TimeSpan.FromSeconds(5);

        public const string TypeName = "BulletBase";
        public const bool IsStandardBullet = false;
        public virtual int RateOfFire { get { return 1000; } }
        public override bool CanDamageEnemy { get { return true; } }

        public BulletBase(GameplayScreen screen, string bulletImage, Vector2? size = null)
            : base(screen, bulletImage, size)
        {
        }

        public override void Update(GameTime gameTime)
        {
            GraphicsDeviceManager gdm = ((Game1)screen.ScreenManager.Game).GDM;
            if (position.X < 0 || position.Y < 0 || position.X > gdm.PreferredBackBufferWidth || position.Y > gdm.PreferredBackBufferHeight)
            {
                if (outOfBounds == null)
                {
                    outOfBounds = DateTime.Now;
                }
                else if ((outOfBounds + outOfBoundsTimeLimit) < DateTime.Now)
                {
                    screen.GOM.DisposeOf(this);
                }
            }
            else if (outOfBounds != null)
            {
                outOfBounds = null;
            }
        }
    }
}
